package com.jsshse.dao.sys.impl;

import java.util.List;
import java.util.Map;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Repository;

import com.jsshse.dao.base.impl.BaseDaoImpl;
import com.jsshse.dao.sys.ParamDaoI;

@Repository("paramDao")
public class ParamDaoImpl <T> extends BaseDaoImpl<T> implements ParamDaoI<T> {

	@Override
	@Caching(evict={@CacheEvict(value="param"),@CacheEvict(value="param_group")}) 
	public boolean add(Map param) {
		String v = (String) this.getSqlTemp().insert("sys.insertParam", param);
		return v != null ? true : false;
	}

	@Override
	@Caching(evict={@CacheEvict(value="param"),@CacheEvict(value="param_group")}) 
	public boolean delete(String id) {
		int res = this.getSqlTemp().delete("sys.deleteParam", id);
		return res > 0 ? true : false;
	}

	@Override
	@Caching(evict={@CacheEvict(value="param"),@CacheEvict(value="param_group")}) 
	public boolean update(Map param) {
		int res =this.getSqlTemp().update("sys.updateParam",param);
		return res > 0 ? true : false;
	}

	@Override
	@Cacheable(value = "param", key ="'queryById'+#id")
	public Map queryById(String id) {
		return (Map) this.getSqlTemp().queryForObject("sys.queryParamById", id);
	}
	
	@Override
	public int queryForListCnt(Object paramCls) {
		return ((Integer) this.getSqlTemp().queryForObject(
				"sys.queryParamForListCnt", paramCls)).intValue();
	}

	@Override
	public List queryForListByPage(Object paramCls, int startRow, int pageRows) {
		return  this.getSqlTemp().queryForList("sys.queryParamForList",
				paramCls, startRow, pageRows);
	} 
 
}
